package tech.com.commoncore.basecomponent;

import tech.com.commoncore.basecomponent.empty_service.EmptyBiFragmentService;
import tech.com.commoncore.basecomponent.empty_service.EmptyFragmentService;
import tech.com.commoncore.basecomponent.empty_service.EmptyLoginService;
import tech.com.commoncore.basecomponent.empty_service.EmptyZiXunService;
import tech.com.commoncore.basecomponent.service.IBiService;
import tech.com.commoncore.basecomponent.service.ICalculatorService;
import tech.com.commoncore.basecomponent.service.ICircleService;
import tech.com.commoncore.basecomponent.service.IFragmentService;
import tech.com.commoncore.basecomponent.service.IHangQingService;
import tech.com.commoncore.basecomponent.service.ILoginService;
import tech.com.commoncore.basecomponent.service.ITaskService;
import tech.com.commoncore.basecomponent.service.IVideoStoreService;
import tech.com.commoncore.basecomponent.service.IZiXunService;

public class ServiceFactory {
    /**
     * 禁止外部创建 ServiceFactory 对象
     */
    private ServiceFactory() {
    }

    /**
     * 通过静态内部类方式实现 ServiceFactory 的单例
     */
    public static ServiceFactory getInstance() {
        return Inner.serviceFactory;
    }

    private static class Inner {
        private static ServiceFactory serviceFactory = new ServiceFactory();
    }

    private ILoginService loginService;
    private IFragmentService homeService;
    private ICircleService circleService;
    private IFragmentService perconalService;
    private IHangQingService hangqingService;
//    private IFragmentService hangqingService;
    private IZiXunService zixunService;
    private IVideoStoreService videoStoreService;
    private ITaskService taskService;
    private ICalculatorService calculatorService;
    private IBiService biService;
    private IFragmentService conversionService;
//    private IHangQingService iHangQingService;
//    private IFragmentService celieFragment;


//    public IFragmentService getCelieFragmentService() {
//        if (celieFragment == null) {
//            celieFragment = new EmptyFragmentService();
//        }
//        return celieFragment;
//    }
//
//    public void setCelieFragmentService(IFragmentService celieFragment) {
//        this.celieFragment = celieFragment;
//    }




    public IBiService getBiService() {
        if (biService == null) {
            biService = new EmptyBiFragmentService();
        }
        return biService;
    }

    public void setBiService(IBiService biService) {
        this.biService = biService;
    }

    //--------------------登录-----------------


    public ICalculatorService getCalculatorService() {
        if (calculatorService == null) {
            calculatorService = new EmptyFragmentService();
        }
        return calculatorService;
    }

    public void setCalculatorService(ICalculatorService calculatorService) {
        this.calculatorService = calculatorService;
    }


    //换算工具
    public IFragmentService getConversionService() {
        if (conversionService == null) {
            conversionService = new EmptyFragmentService();
        }
        return conversionService;
    }

    public void setConversionService(IFragmentService conversionService) {
        this.conversionService = conversionService;
    }




    /**
     * 接收 Login 组件实现的 Service 实例
     */
    public void setLoginService(ILoginService loginService) {
        this.loginService = loginService;
    }

    /**
     * 返回 Login 组件的 Service 实例
     */
    public ILoginService getLoginService() {
        if (loginService == null) {
            loginService = new EmptyLoginService();
        }
        return loginService;
    }

    //--------------------主页-----------------

    /**
     * 接收 home 组件实现的 Service 实例
     */
    public void setHomeService(IFragmentService homeService) {
        this.homeService = homeService;
    }

    /**
     * 返回 home 组件的 Service 实例
     */
    public IFragmentService getHomeService() {
        if (homeService == null) {
            homeService = new EmptyFragmentService();
        }
        return homeService;
    }

    //--------------------行情-----------------

    /**
     * 接收 行情 组件实现的 Service 实例
     *
     * IFragmentService hangqingService
     */
    public void setHangqingService(IHangQingService hangqingService) {
        this.hangqingService = hangqingService;
    }

    /**
     * 返回 行情 组件的 Service 实例
     */
    public IHangQingService getHangqingService() {
        if (hangqingService == null) {
            hangqingService = new EmptyFragmentService();
        }
        return hangqingService;
    }

    //-------------------论坛----------------

    /**
     * 接收 圈子 组件实现的 Service 实例
     */
    public void setCircleService(ICircleService circleService) {
        this.circleService = circleService;
    }

    /**
     * 返回 圈子 组件的 Service 实例
     */
    public ICircleService getCircleService() {
        if (circleService == null) {
            circleService = new EmptyFragmentService();
        }
        return circleService;
    }


    //--------------------个人中心--------------------

    /**
     * 接收 个人中心 组件实现的 Service 实例
     */
    public void setPerconalService(IFragmentService perconalService) {
        this.perconalService = perconalService;
    }

    /**
     * 返回 个人中心 组件的 Service 实例
     */
    public IFragmentService getPerconalService() {
        if (perconalService == null) {
            perconalService = new EmptyFragmentService();
        }
        return perconalService;
    }

    //-----------------------资讯------------------------
    public void setZixunService(IZiXunService zixunService) {
        this.zixunService = zixunService;
    }

    public IZiXunService getZixunService() {
        if (zixunService == null) {
            zixunService = new EmptyZiXunService();
        }
        return zixunService;
    }

    //-----------------------视频商城------------------------
    public IVideoStoreService getVideoStoreService() {
        if (videoStoreService == null) {
            videoStoreService = new EmptyFragmentService();
        }
        return videoStoreService;
    }

    public void setVideoStoreService(IVideoStoreService service) {
        this.videoStoreService = service;
    }

    //--------------------------任务模块----------------------------
    public void setTaskService(ITaskService service) {
        if (service == null) {
            taskService = new EmptyFragmentService();
        }
        this.taskService = service;
    }

    public ITaskService getTakServide() {
        if (taskService == null) {
            taskService = new EmptyFragmentService();
        }
        return taskService;
    }

}
